using UnityEngine;
using System.Collections;

public class TargetMover : MonoBehaviour {
	
	//Mask for the raycast
	public LayerMask mask;
	
	public Transform target;
	
	Camera cam;
	
	public void Start () {
		//Cache the Main Camera
		cam = Camera.main;
	}
	
	// Update is called once per frame
	void Update () {
		
		if (cam != null) {
			
			//Fire a ray through the scene at the mouse position and place the target where it hits
			RaycastHit hit;
			if (Physics.Raycast	(cam.ScreenPointToRay (Input.mousePosition), out hit, Mathf.Infinity, mask)) {
				target.position = hit.point;
			}
		}
		
	}
	
}
